(function() {
    $(document).ready(function() {
        var hashChanged = false;
        function hashUpdate() {
            $("a").each(function() {

                if($(this).attr('href') == location.hash) {
                    $(this).click();
                    $(this).parent().parent().find("li").removeClass('active');
                    $(this).parent().addClass('active');
                }
            });
            if(location.toString().indexOf('#') != -1 && location.toString().indexOf('#') != (location.length - 1))
                location.hash = "";
        }

        $(window).hashchange(hashUpdate);
        hashUpdate();
    });
})(window, document);